<template>
  <a-modal
    :title="this.title"
    :visible="this.visible"
    :width="860"
    :footer="null"
    @cancel="cancel"
    @ok="ok"

  >
  <div style="text-align:center">
  	 <a-input  class="searchCriteria" placeholder="请输入应用名称" v-model="searchKey" @keyup.enter.native="searchApp" style="width:60%;margin-bottom:20px"/>
    <a-card v-if="appArray.length>0">
          <a-card-grid style="width:25%;text-align:center" v-for="(item, index) of appArray" :key='index'>
               <router-link :to="{path:'/dataManage/dashboard',query:{system:'数据管理'}}" v-if="item.sysCode==='S002'">
                       <span @click="gotoMenu(item)">{{item.sysName}}</span>
               </router-link>
               <router-link :to="{path:'/businessManage/dashboard',query:{system:'业务管理'}}" v-else-if="item.sysCode==='S001' ">
                       <span @click="gotoMenu(item)">{{item.sysName}}</span>
               </router-link>
               <router-link :to="{path:'/permissionManage/dashboard',query:{system:'权限管理'}}" v-else-if="item.sysCode==='S000' && isManager('S000')">
                       <span @click="gotoMenu(item)">{{item.sysName}}</span>
               </router-link>
               <a  target="_blank" v-else>
                      <span @click="gotoNext(item)" style="color:#007BFF">{{item.sysName}}</span>
               </a>
           </a-card-grid>
     </a-card>
     <p v-else>暂无数据</p>
     <a-pagination v-model="current" :total="this.total" :pageSize="this.limit" show-less-items @change="onChange" style="margin-top:20px" />

  </div>

  </a-modal>
</template>

<script>
  import aModal from "@/common/modal"
  import global from "@/../static/global.vue"
  import {GETAVAILABLEAPP,COUNTACCESS} from '@/../static/js/apis.js'
  export default {
    name: "appModal",
    props: ['title', 'visible'],
    components: {
      aModal
    },

    data() {
      return {
          current: 1,
          total:0,
          limit:16,
          appArray:[],
          searchKey:''
      }
    },
    methods: {
      isManager (value) {
        return global.isManager(value)
      },
        /*获取静态数据*/
        getStaticData(page,keyWord) {
          let self = this
          var params={
            limit:self.limit,
            page:page,
            keyWord:keyWord
          }
          GETAVAILABLEAPP(params, function (res) {
               self.total=res.totals
               self.appArray=res.list
          })
      },
      onChange(page, pageSize) {
          this.getStaticData(page,'')
      },
      searchApp(){
          this.getStaticData(1,this.searchKey)
      },
       gotoMenu(item){
         COUNTACCESS({sysCode:item.sysCode}, function (res) {
        })
        this.$store.commit('changeFirstNavSelected', '0')
       },
      gotoNext(item){
           COUNTACCESS({sysCode:item.sysCode}, function (res) {
            })
        if (item.url.indexOf('?') > -1) {
           var url2 = item.url + '&token=' + localStorage.getItem('token')
          // var url2 = item.url
          console.log(url2)
          window.open(url2,'_blank') //item.url + '&token=' + localStorage.getItem('token')
        } else {
           let url3 = item.url + '?token=' + localStorage.getItem('token')
          // var url3 = item.url
          console.log(url3)
          window.open(url3,'_blank')// item.url + '?token=' + localStorage.getItem('token')
        }
     },
    	 ok(e) {
         this.current=1
         this.searchKey=''
         this.getStaticData(1,'')
         this.$emit("cancel", e)
      },
    	 /*关闭modal*/
      cancel(e) {
        this.current=1
        this.searchKey=''
        this.getStaticData(1,'')
        this.$emit("cancel", e)
      },
    },
    created () {
      this.getStaticData(1,'')
    },

  }
</script>

<style scoped>

</style>
